using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;

public class CtrlTank : BaseTank
{
    float x, y;
    Vector3 s;
    float axis;
    Vector3 le;
    private void Awake()
    {
        
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }


    // Update is called once per frame
    void Update()
    {
        if (IsDie())
        {
            return;
        }
        Move();
        Turret();
        Fire();
    }

    private void Fire()
    {
        if (!Input.GetKey(KeyCode.Space))
        {
            return;
        }
        if(Time.time -lastFireTime<fireCd)
        {
            return;
        }
        BulletFire();
    }

    private void Turret()
    {
        if (Input.GetKey(KeyCode.Q))
        {
            axis = -1;
        }else if (Input.GetKey(KeyCode.E))
        {
            axis = 1;
        }
        else
        {
            axis = 0;
        }
        Vector3 le = turret.localEulerAngles;
        le.y += axis * Time.deltaTime * turretSpeed;
        turret.localEulerAngles = le;
    }

    private void Move()
    {
        x = Input.GetAxis("Horizontal");
        transform.Rotate(0, x * steer * Time.deltaTime, 0);
        y = Input.GetAxis("Vertical");
        s = y * transform.forward * speed * Time.deltaTime;
        transform.transform.position += s;
    }
}
